package logic

import (
	"context"
	"errors"
	"video-management-system/model"

	"video-management-system/userrpc/internal/svc"
	"video-management-system/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 取消收藏
func (l *CollectDelLogic) CollectDel(in *userrpc.CollectDelRequest) (*userrpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line
	var findCollect model.CollectionInfo
	err := findCollect.FindCollectById(model.DB, in)
	if err != nil {
		return nil, err
	}
	if findCollect.ID == 0 {
		return nil, errors.New("收藏不存在")
	}
	var collect model.CommentInfo
	err = collect.CollectDel(model.DB, in)
	if err != nil {
		return nil, errors.New("删除失败")
	}
	return &userrpc.CollectDelResponse{}, nil
}
